using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UpgradeExtraMove:Upgrade {
	protected override void SubscribeEvents() {
		base.SubscribeEvents();
		ActionSkillSlot.SkillActivate+=SkillActivateEventHandler;
	}

	public override void UnsubscribeEvents() {
		base.UnsubscribeEvents();
		ActionSkillSlot.SkillActivate-=SkillActivateEventHandler;
	}

	ActionSkillSlot skill;
	bool gotSkill;

	void SkillActivateEventHandler(object _sender) {
		ActionSkillSlot sender = _sender as ActionSkillSlot;
		if(sender==null||sender.mob!=weapon.owner) return;
		weapon.weapon.currentClip.AddRound(AmmoManager.nameToId["gold"],true);
		skill=sender;
		gotSkill=true;
	}

	protected override void ShootingEventHandler(object sender,ShootEventArgs e) {
		if(!IfReactWeaponEvent(sender,e)) return;
		if(!gotSkill) {
			skill=(sender as Weapon).owner.GetComponent<ActionSkillSlot>();
			gotSkill=true;
		}
		if(gotSkill&&skill==null) return;
		if(e.stat.consumedAmmos.ContainsKey(AmmoManager.nameToId["gold"])) {
			int amount = e.stat.consumedAmmos[AmmoManager.nameToId["gold"]];
			skill.actionSkill.ReduceCooldown(0.15f*amount);
		}
	}

}
